/**
 * @file    common_msg_queue.h
 * @author  yhy
 * @brief   消息队列
 * @version 1.00
 * @date    2025-07-09
 *
 * @copyright Copyright (c) 2025
 *
 * Change Logs:
 * Date           Author       Notes
 * 2025-07-02     yhy          the first version V1.00
 *
 */
#ifndef __COMMON_MSG_QUEUE_H__
#define __COMMON_MSG_QUEUE_H__

#include "common_config.h"

#include <stdbool.h>
#include <stdint.h>

#define MASSAGE_QUEUE_BUFFER_MAXSIZE 48 /* 消息帧缓冲区最大值 */

/* 消息帧 */
typedef struct
{
    uint32_t msg_id;   /*!< 消息id */
    uint32_t data_len; /*!< 数据长度h */
    uint8_t  data[64]; /*!< 数据 */
} msg_frame_t;

/* 消息队列 */
typedef struct
{
    uint32_t     front;         /*!< 队首*/
    uint32_t     rear;          /*!< 队尾 */
    uint32_t     count;         /*!< 队列成员数量 */
    msg_frame_t *msg_frame_buf; /*!< 消息帧缓冲区 */
    uint32_t     depth;         /*!< 队列深度 */
} msg_queue_t;

void     common_queue_init(msg_queue_t *queue, msg_frame_t *can_buf, uint32_t depth);
bool     common_queue_is_empty(msg_queue_t *queue);
bool     common_queue_is_full(msg_queue_t *queue);
bool     common_queue_push(msg_queue_t *queue, msg_frame_t can_frame);
bool     common_queue_pop(msg_queue_t *queue, msg_frame_t *can_frame);
uint16_t common_queue_get_free_depth(msg_queue_t *queue);

#endif
